
import request from '../../utils/request.js'
const state = {
	homeInfo:{},
	cardList:[]
}

const actions = {
	// 1. 页面中的数据
	async getHomeInfoData({commit}){
		try{
			const result =await request({url:'/getIndexData'})

			commit('SET_HOME_INFO_DATA',result)
		}catch(e){
			console.log(e)
		}
	},
	// 2. 导航项分类数据
	async getHomeCardListData({commit}){
		try{
			const result = await request({url:'/getIndexCateList'})
			console.log('card',result)
			commit('SET_HOME_CARD_LIST_DATA',result)
		}catch(e){
			console.log(e.message)
		}
	}
}

const mutations = {
	//  homeInfo对象 赋值
	SET_HOME_INFO_DATA(state,result){
		state.homeInfo = result
	},
	// 存储主页面分类数据项
	SET_HOME_CARD_LIST_DATA(state,arr){
		state.cardList = arr
	}
}
//
const getters = {
	
	navList(state){

		return (state.homeInfo.kingKongModule || {}).kingKongList || []
	},
	
	sloganList(state){

		return state.homeInfo.policyDescList || []
	},

	floorsList(state){
		return state.homeInfo.categoryModule || []
	}
}

export default {
	namespaced: true, 
	state,
	actions,
	mutations,
	getters
}